/**
 * Created by Daniel on 7/11/16.
 */
import alt from '../alt';
import FooterActions from '../actions/FooterActions';

/**
 * 这里的store做了几件事:
 * 1. 和Footer的action绑定在一起,绑定就等价于订阅了actions.
 * 2. 初始化了一个characters空数组,这个空数组会和React的state绑定  参考文档:http://alt.js.org/docs/createStore/#storemodelbindlisteners
 */
class FooterStore {
    constructor() {
        this.bindActions(FooterActions);
        this.characters = [];
    }

    onGetTopCharactersSuccess(data) {
        this.characters = data.slice(0, 5);
    }

    onGetTopCharactersFail(jqXhr) {
        // Handle multiple response formats, fallback to HTTP status code number.
        toastr.error(jqXhr.responseJSON && jqXhr.responseJSON.message || jqXhr.responseText || jqXhr.statusText);
    }
}

export default alt.createStore(FooterStore);